<?php
require_once 'buildCurl.php';
$res = json_decode(file_get_contents('php://input'), true);


$captcha = $res['captcha'];
$id = $res['id'];
$password = $res['password'];
$session = $res['session'];

$url = "http://211.82.48.36/j_spring_security_check";
$post = "j_username=" . $id . "&j_password=" . md5($password) . "&j_captcha=" . $captcha;

$myCurl = new MyPostCurl($url, $session, $post, 1);
$result = $myCurl->getResult();
$httpCode = $myCurl->getHttpCode();

preg_match('/Location:([^\r\n]*)/i', $result, $str); 
$return_url = $str[1];

if ($return_url == " http://211.82.48.36/" || $return_url == "http://211.82.48.36/index.jsp") {
     $arr = array('err' => 0);
    exit(json_encode($arr));
}

$errCode = explode("?errorCode=", $return_url)[1];
if ($errCode == 'badCaptcha') {
    $arr = array('err' => 1, 'errmsg' => '验证码输入错误');
    exit(json_encode($arr));
}

if ($errCode == 'badCredentials') {
    $arr = array('err' => 2, 'errmsg' => '账号或密码错误，连续错误将无法登录！');
    exit(json_encode($arr));
}
